#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from rclpy.action import ActionClient
from general_interface.action import AutoTask


class ActionClientNode(Node):
    def __init__(self):
        super().__init__("action_client_node")
        self.action_client = ActionClient(self, AutoTask, "connect_task")

        goal_msg = AutoTask.Goal()
        params = goal_msg.get_fields_and_field_types()
        print(params)
        
        self.action_client.wait_for_server()
        self.invokeAction()

    def invokeAction(self):
        goal_msg = AutoTask.Goal()
        params = goal_msg.get_fields_and_field_types()
        print(params)
        future = self.action_client.send_goal_async(goal_msg)


if __name__ == "__main__":
    rclpy.init()
    action_client_node = ActionClientNode()
    action_client_node.get_logger().info("Action invoke node started")
    rclpy.spin(action_client_node)
    rclpy.shutdown()
